package cn.onlineclass.service;


import cn.onlineclass.dao.OVideoMapper;
import cn.onlineclass.entity.OVideo;
import cn.onlineclass.util.AjaxPage;
import cn.onlineclass.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class videoService {
    private static Logger Log = LoggerFactory.getLogger(videoService.class);
    public static final videoService TYPE = new videoService();

    public int add(OVideo a){
        SqlSession s= MybatisUtil.get();
        try {
            OVideoMapper mapper = s.getMapper(OVideoMapper.class);
            return mapper.add(a);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public AjaxPage search(int pageNo, int pageSize, String title,String bookid){
        SqlSession s= MybatisUtil.get();
        OVideoMapper mapper = s.getMapper(OVideoMapper.class);
        try {
            List<OVideo> products = mapper.search(pageNo,10,title,bookid);
            int total = mapper.searchTotal(title,bookid);
            return  new AjaxPage(products,total,pageNo,pageSize);
        }catch (Exception e){
            System.out.println(e.getMessage());
            return null;
        }finally {
            MybatisUtil.closeSession(s);
        }
    }


    public int del(OVideo id) {
        SqlSession s= MybatisUtil.get();
        try {
            OVideoMapper mapper = s.getMapper(OVideoMapper.class);
            return mapper.del(id);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public int update(OVideo p){
        SqlSession s= MybatisUtil.get();
        try {
            OVideoMapper mapper = s.getMapper(OVideoMapper.class);
            return mapper.update(p);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public OVideo get(long id){
        SqlSession s= MybatisUtil.get();
        try {
            OVideoMapper mapper = s.getMapper(OVideoMapper.class);
            return mapper.get(id);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }

}
